<template>
    <div class="page-100 examine-adddes-layout">
        <textarea
                v-model="content"
                class="weui-textarea" style="border-bottom: 1px solid #e6e6e6;border-top: 1px solid #e6e6e6;  font-size: 1.2em;
        text-align: left;
        padding-top: 0.3rem;
        padding-left: 0.3rem;
        padding-right: 0.3rem"
                :placeholder=placeholder
                rows="5"
                maxlength="200"></textarea>

        <!--发送按钮-->

        <yd-button  size="large" type="primary" @click.native="handleClick" style="background-color:#3cc8a8;color:white;height: 40px">发送</yd-button>

    </div>
</template>

<script>
    import {userInfoData} from '../../globalVariables'
    import {orderaccept,orderrefuse,orderoperateRefuse} from "../../pcof/post";
    export default {
        name: "officeExaminandoperate",

        data() {
            return {
                orderUuid: '',
                content: '',
                placeholder:'',
                type: '', //1 审核同意 2是审核拒绝 3经办拒绝
            }
        },
        methods: {
           async handleClick()
            {

                if (this.type ==='1')
                {
                    /**
                     * 审批意见 同意
                     *  orderUuid 单子的id
                     */
                    //  orderaccept
                    //   mobile,orderUuid,content,

                    // 办公用品详情页 orderUuid 单子的id  orderDetails
                    var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                    console.log(this.orderUuid);
                    this.$dialog.loading.open('加载中...');
                    var response = await orderaccept(mobile, this.orderUuid,this.content);
                    if (response.data.code === 200) {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: '已同意',
                            timeout: 1500
                        });
                        this.$router.replace({name: 'wait'});

                    } else {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: response.data.msg,
                            timeout: 1500
                        });
                    }

                }else  if (this.type ==='2')
                {
                    /**
                     * 审批意见 拒绝
                     *  orderUuid 单子的id
                     */
                    // export const orderrefuse = (

                    // 办公用品详情页 orderUuid 单子的id  orderDetails
                    var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                    console.log(this.orderUuid);
                    this.$dialog.loading.open('加载中...');
                    var response = await orderrefuse(mobile, this.orderUuid,this.content);
                    if (response.data.code === 200) {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: '已拒绝',
                            timeout: 1500
                        });
                        this.$router.replace({name: 'wait'});

                    } else {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: response.data.msg,
                            timeout: 1500
                        });
                    }


                }else  if (this.type ==='3')
                {
                    /**
                     * 经办 拒绝
                     *  orderUuid 单子的id
                     *  content 输入你内容
                     */
                    //  orderoperateRefuse

                    if (this.content === '' || this.content === null) {
                        this.$dialog.toast({
                            mes: '拒绝原因必须输入！',
                            timeout: 1500
                        });
                        return;
                    }
                    // 办公用品详情页 orderUuid 单子的id  orderDetails
                    var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                    console.log(this.orderUuid);
                    this.$dialog.loading.open('加载中...');
                    var response = await orderoperateRefuse(mobile, this.orderUuid,this.content);
                    if (response.data.code === 200) {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: '已通知发起人',
                            timeout: 1500
                        });
                        this.$router.replace({name: 'wait'});

                    } else {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: response.data.msg,
                            timeout: 1500
                        });
                    }

                }

            },

        },
        created(){
            this.type=this.$route.params.type;
            this.orderUuid =  this.$route.params.orderUuid;
            console.log('数据'+this.orderUuid);

            //1 审核同意 2是审核拒绝 3经办拒绝
            if (this.type ==='1') {
             this.placeholder='输入审批意见（非必填）...';
            }else if(this.type ==='2')
            {
                this.placeholder='输入审批意见（非必填）...';

            }else  if (this.type ==='3')
            {
                this.placeholder='输入拒绝原因（必填）...';

            }



        }
    }
</script>

<style lang="scss">
    .examine-adddes-layout {

        background-color: #f3f3f3;
    .des-fault-part {
        border: 0;
        font-size: 1.2em;
        text-align: left;
        padding-top: 0.3rem;
        padding-left: 0.3rem;
        padding-right: 0.3rem;
    }

    .send-button-part {
        margin-left: 0.6rem;
        margin-right: 0.6rem;
    }
    }
</style>